document
  .getElementById("registerForm")
  .addEventListener("submit", function (e) {
    e.preventDefault();
    const data = {
      username: document.getElementById("username").value,
      password: document.getElementById("password").value,
      question: document.getElementById("question").value,
      answer: document.getElementById("answer").value,
    };

    axios
      .post("http://localhost:4407/api/User/register", data)
      .then((response) => {
        const data = response.data;
        console.log(data);
        if (data.msg === "注册成功") {
          localStorage.setItem("token", data.token);
          window.location.href = "Login.html";
        } else {
          alert("注册失败: " + data.msg);
        }
      })
      .catch((error) => console.error("Error:", error));
  });
